package com.zeropoint.demo.filter;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.PrintWriter;

public class LoginFilter extends FormAuthenticationFilter {
 
    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
        System.out.println("未登录执行");
        response.setContentType("application/json;charset=utf-8");
        PrintWriter writer = response.getWriter();
        ObjectMapper objectMapper = new ObjectMapper();
        /*CommonResult commonResult = new CommonResult(5001, "未登录", null);
        String value = objectMapper.writeValueAsString(commonResult);
        writer.println(value);*/
        writer.flush();
        writer.close();
        return false;
    }
}